package com.ht.medicaltreatment.activity

import android.view.View
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.gym.baselib.base.BaseActivity
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.adapter.ShenQingDetailAdapter
import com.ht.medicaltreatment.view.ShenPiDailog
import com.ht.medicaltreatment.viewmodel.HaoCaiDetailViewModel
import kotlinx.android.synthetic.main.activity_shenqing_detail_layout.btnCreate
import kotlinx.android.synthetic.main.activity_shenqing_detail_layout.btnDelete
import kotlinx.android.synthetic.main.activity_shenqing_detail_layout.etFormName
import kotlinx.android.synthetic.main.activity_shenqing_detail_layout.etProjectCode
import kotlinx.android.synthetic.main.activity_shenqing_detail_layout.etSampleName
import kotlinx.android.synthetic.main.activity_shenqing_detail_layout.etUser
import kotlinx.android.synthetic.main.activity_shenqing_detail_layout.recyclerView
import kotlinx.android.synthetic.main.activity_shenqing_detail_layout.tvRemark

//耗材申请 的详情页面
class ShenQingDetailActivity : BaseActivity(){

    override fun getLayoutId() = R.layout.activity_shenqing_detail_layout

    private val model by viewModels<HaoCaiDetailViewModel>()

    override fun init() {
        setTitle("耗材申请详情")
        val id = intent.getIntExtra("id",-1)

        recyclerView.layoutManager = LinearLayoutManager(this)
        val adapter = ShenQingDetailAdapter()
        recyclerView.adapter = adapter
        //拒绝
        btnDelete.setOnClickListener {
            ShenPiDailog(this).show {
                showProgress()
                model.shenPi("$id",it,"2"){
                    dismissProgress()
                    finish()
                }
            }
        }

        //同意
        btnCreate.setOnClickListener {
            showProgress()
            model.shenPi("$id","","1"){
                dismissProgress()
                finish()
            }
        }

        showProgress()
        model.getDetail("$id"){
            dismissProgress()
            etFormName.text = it.projectConsumableRecord.name
            //申请人
            etSampleName.text = it.projectConsumableRecord.username

            etUser.text = it.projectConsumableRecord.createTime
            if(it.projectConsumableRecord.status == 0){
                etProjectCode.text = "待审批"
            }else if(it.projectConsumableRecord.status == 1){
                etProjectCode.text = "同意"
            }else if(it.projectConsumableRecord.status == 2){
                etProjectCode.text = "驳回"
            }
            tvRemark.text = it.projectConsumableRecord.remark
            adapter.setNewInstance(it.projectConsumableRecord.projectConsumableRecordDetailsList)

            if(it.authSign == 1 && it.projectConsumableRecord.status == 0){
                btnDelete.visibility = View.VISIBLE
                btnCreate.visibility = View.VISIBLE
            }
        }
    }
}
